package com.wcr.school.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wcr.school.pojo.Clazz;
import com.wcr.school.service.ClazzService;
import com.wcr.school.util.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/sms/clazzController")
public class ClazzController {
    @Autowired
    ClazzService clazzService;//当实现类唯一时，表面上注入接口，其实注入实现类

    @ApiOperation("查询所有班级")//接口文档注解
    @GetMapping("/getClazzs")
    public Result getClazzs(){
        List<Clazz> list = clazzService.allClazzName();
        return Result.ok(list);
    }


    @GetMapping("/getClazzsByOpr/{pageNo}/{pageSize}")
    public Result getGrades(
            @PathVariable("pageNo") Integer pageNo,
            @PathVariable("pageSize") Integer pageSize,
            Clazz clazz
    )
    {
        //分页，带条件查询
        Page<Clazz> page = new Page<>(pageNo,pageSize);
        //通过服务层
        IPage<Clazz> iPage = clazzService.getClazzByOption(page,clazz);
        //封装return返回
        return Result.ok(iPage);

    }
    @PostMapping("/saveOrUpdateClazz")
    public Result saveOrUpdateClazz(@RequestBody Clazz clazz){
        clazzService.saveOrUpdate(clazz);
        return Result.ok();
    }

    @DeleteMapping("/deleteClazz")
    public Result deleteTeacher(@RequestBody List<Integer> list){
        clazzService.removeByIds(list);
        return Result.ok();
    }
}
